@extends('admin.layouts')
@section('css')
    <link href="{{asset('assets/css/bootstrap.min.css')}}" rel="stylesheet" />
    <link rel="stylesheet" href="{{asset('assets/css/font-awesome.min.css')}}" />
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />

    <!-- ace styles -->

    <link rel="stylesheet" href="{{asset('assets/css/ace.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-rtl.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-skins.min.css')}}" />
    <script src="{{asset('assets/js/ace-extra.min.js')}}"></script>
@endsection
@section('content')
    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <script type="text/javascript">
                try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
            </script>

            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="{{url('admin/index')}}">主页</a>
                </li>

                <li>
                    <a>公告</a>
                </li>
                <li class="active">
                    公告管理
                </li>
            </ul><!-- .breadcrumb -->

            <div class="nav-search" id="nav-search">
                <form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
									<i class="icon-search nav-search-icon"></i>
								</span>
                </form>
            </div><!-- #nav-search -->
        </div>

        <div class="page-content">
            <div class="page-header">
                <h1>
                    公告管理
                </h1>
            </div><!-- /.page-header -->
            <!-- 模态框（Modal） -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">发布公告</h4>
                        </div>
                        <div class="modal-body">
                            <textarea name="notice" id="notice" style="width: 100%" rows="10"></textarea>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <input type="button" class="btn btn-primary" onclick="adfsdf()" value="提交">
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>

            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->

                    <div class="row">
                        <div class="col-xs-12">
                            <button class="btn btn-success" data-toggle="modal" data-target="#myModal">发布公告</button>
                            <hr>
                            <div class="table-responsive">
                                <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>内容</th>
                                        <th>状态</th>
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            创建时间
                                        </th>
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            更新时间
                                        </th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>

                                    <tbody>
                                    @if(sizeof($notices)>0)
                                        @foreach($notices as $cate)
                                            <tr id="id{{$cate['id']}}">
                                                <td>
                                                    {{$cate['id']}}
                                                </td>
                                                <td>{{$cate['notice']}}</td>
                                                <td class="hidden-480">
                                                    @if($cate['status']==1)
                                                        <span class="label label-sm label-success">
                                                <i class="icon-ok bigger-120"></i>显示
                                            </span>
                                                    @else
                                                        <span class="label label-sm label-danger">
                                                <i class="icon-remove bigger-120"></i>不显示
                                            </span>
                                                    @endif
                                                </td>
                                                <td>{{date('Y-m-d H:i:s',$cate['created_at'])}}</td>
                                                <td>{{date('Y-m-d H:i:s',$cate['updated_at'])}}</td>
                                                <td>
                                                    @if($cate['status']==1)
                                                        <button role="button" onclick="upstatus({{$cate['id']}},0)" class="btn-danger btn-xs btn">隐藏</button>
                                                    @else
                                                        <button role="button" class="btn-info btn-xs btn" onclick="upstatus({{$cate['id']}},1)">显示</button>
                                                    @endif
                                                    <button role="button" onclick="deletec({{$cate['id']}})" class="btn-danger btn-xs btn">删除</button>
                                                </td>
                                            </tr>
                                        @endforeach
                                    @else
                                        <tr>
                                            <td style="text-align: center" colspan="11">什么都没有啦</td>
                                        </tr>
                                    @endif
                                    </tbody>
                                </table>
                            </div><!-- /.table-responsive -->
                        </div><!-- /span -->
                    </div><!-- /row -->

                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->
@endsection
@section('javascript')
    <script src='{{asset('assets/js/jquery-2.0.3.min.js')}}'></script>
    <script src="{{asset('assets/js/bootstrap.min.js')}}"></script>
    <script src="{{asset('assets/js/typeahead-bs2.min.js')}}"></script>

    <!-- ace scripts -->
    <script type="text/javascript" src="{{asset('assets/layer/layer.js')}}"></script>
    <script src="{{asset('assets/js/ace-elements.min.js')}}"></script>
    <script src="{{asset('assets/js/ace.min.js')}}"></script>
    <script>
        function adfsdf(){
            var notice=$("#notice").val();
            $.post('{{url('admin/addnotice')}}',{'_token':'{{csrf_token()}}','notice':notice}, function (res) {
                layer.msg(res.msg);
                if(res.status){
                    location.reload();
                }
            });
        }

        function upstatus(id,status){
            layer.load(2);
            $.post('{{url('admin/updatenoticestatus')}}',{'_token':'{{csrf_token()}}','id':id,'status':status},function(res){
                layer.closeAll('loading');
                if(res.status){
                    layer.msg(res.msg);
                    location.reload(true);
                }else{
                    layer.msg(res.msg);
                }
            });
        }

        function deletec(id){
            layer.confirm('你确定要删除吗？',{
                btn:['确定','取消']
            },function(){
                layer.load(2);
                $.post('{{url('admin/deletenotice')}}',{'_token':'{{csrf_token()}}','id':id}, function (res) {
                    layer.closeAll('loading');
                    if(res.status){
                        $("#id"+id).remove();
                        layer.msg(res.msg);
                    }else{
                        layer.msg(res.msg);
                    }
                });
            },function(){

            });
        }
    </script>
@endsection